package com.tedu.ds.advertisement.service.impl;

import com.tedu.ds.advertisement.mapper.AdvertisementMapper;
import com.tedu.ds.advertisement.pojo.dto.AdvertisementParam;
import com.tedu.ds.advertisement.pojo.dto.AdvertisementQuery;
import com.tedu.ds.advertisement.pojo.entity.Advertisement;
import com.tedu.ds.advertisement.pojo.vo.AdvertisementVO;
import com.tedu.ds.advertisement.service.AdvertisementService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdvertisementServiceImpl implements AdvertisementService {
    @Autowired
    private AdvertisementMapper advertisementMapper;

    @Override
    public List<AdvertisementVO> select(AdvertisementQuery advertisementQuery) {
        return advertisementMapper.select(advertisementQuery);
    }

    @Override
    public void save(AdvertisementParam advertisementParam) {
        Advertisement advertisement = new Advertisement();
        BeanUtils.copyProperties(advertisementParam, advertisement);
        if (advertisement.getId() == null) {
            advertisementMapper.insert(advertisement);
        } else {
            advertisementMapper.update(advertisement);
        }
    }

    @Override
    public void delete(Integer id) {
        advertisementMapper.delete(id);
    }

    @Override
    public void updateStatus(Integer id, String status) {
        Advertisement advertisement = new Advertisement();
        advertisement.setId(id);
        advertisement.setStatus(status);
        advertisementMapper.update(advertisement);
    }
}
